Skip to content

Conversation

@sshekhar563
Copy link
Contributor

There is an inconsistency in how the Classes type is handled between component props and standard HTML element attributes.

When passing a Classes prop to a Yew component, it can be passed directly without needing to call .clone(). However, when passing the same Classes value to an HTML element's class attribute, the compiler fails with a trait bound error, forcing the developer to explicitly call .clone().

This behavior is unintuitive and inconsistent, as one would expect the html! macro to handle both cases similarly.

@github-actions
Copy link

github-actions bot commented Oct 11, 2025

Benchmark - core

Yew Master

vnode           fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ vnode_clone  2.463 ns      │ 3.734 ns      │ 2.467 ns      │ 2.546 ns      │ 100     │ 1000000000

Pull Request

vnode           fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ vnode_clone  2.31 ns       │ 2.345 ns      │ 2.315 ns      │ 2.316 ns      │ 100     │ 1000000000

@github-actions
Copy link

github-actions bot commented Oct 11, 2025

Benchmark - SSR

Yew Master

Details
Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 310.535 312.108 310.853 0.485
Hello World 10 531.843 546.184 537.575 5.242
Function Router 10 1704.364 1746.592 1720.668 16.352
Concurrent Task 10 1005.259 1007.831 1006.664 0.855
Many Providers 10 1113.824 1148.390 1127.551 12.389

Pull Request

Details
Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 310.565 313.683 311.068 0.932
Hello World 10 516.956 527.916 519.579 3.236
Function Router 10 1721.441 1744.502 1736.970 6.518
Concurrent Task 10 1005.599 1007.256 1006.597 0.568
Many Providers 10 1087.177 1147.965 1105.281 18.790

@WorldSEnder WorldSEnder added the A-yew Area: The main yew crate label Oct 22, 2025
@github-actions
Copy link

github-actions bot commented Oct 22, 2025

Visit the preview URL for this PR (updated for commit 02efc44):

https://yew-rs-api--pr3931-fix-classes-implicit-y7ul53kb.web.app

(expires Wed, 29 Oct 2025 13:48:06 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

@github-actions
Copy link

github-actions bot commented Oct 22, 2025

Size Comparison

Details
examples master (KB) pull request (KB) diff (KB) diff (%)
async_clock 98.325 98.325 0 0.000%
boids 167.644 167.644 0 0.000%
communication_child_to_parent 91.488 91.488 0 0.000%
communication_grandchild_with_grandparent 102.600 102.600 0 0.000%
communication_grandparent_to_grandchild 98.950 98.950 0 0.000%
communication_parent_to_child 88.812 88.812 0 0.000%
contexts 103.931 103.931 0 0.000%
counter 85.988 85.988 0 0.000%
counter_functional 86.129 86.129 0 0.000%
dyn_create_destroy_apps 88.907 88.907 0 0.000%
file_upload 97.851 97.851 0 0.000%
function_delayed_input 91.048 91.048 0 0.000%
function_memory_game 170.111 170.140 +0.028 +0.017%
function_router 330.215 330.242 +0.027 +0.008%
function_todomvc 162.543 162.571 +0.028 +0.017%
futures 237.354 237.354 0 0.000%
game_of_life 104.080 104.108 +0.028 +0.027%
immutable 194.814 194.814 0 0.000%
inner_html 79.844 79.844 0 0.000%
js_callback 107.788 107.788 0 0.000%
keyed_list 180.234 180.234 0 0.000%
mount_point 83.180 83.180 0 0.000%
nested_list 114.258 114.286 +0.028 +0.025%
node_refs 90.825 90.825 0 0.000%
password_strength 1751.711 1751.711 0 0.000%
portals 92.810 92.810 0 0.000%
router 303.848 303.876 +0.028 +0.009%
suspense 112.123 112.123 0 0.000%
timer 88.080 88.080 0 0.000%
timer_functional 95.812 95.812 0 0.000%
todomvc 142.688 142.716 +0.028 +0.020%
two_apps 85.218 85.218 0 0.000%
web_worker_fib 133.267 133.267 0 0.000%
web_worker_prime 185.155 185.155 0 0.000%
webgl 82.509 82.509 0 0.000%

✅ None of the examples has changed their size significantly.

adds an additional candidate to the impl block, which is fine
Copy link
Member

@WorldSEnder WorldSEnder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. If implicit-clone ever gets a trait for Into that automatically uses ImplicitClone for references, that would make this less of a manual effort to keep track of the impls.

Thanks for the PR 🎉

@WorldSEnder WorldSEnder merged commit 38e7f2b into yewstack:master Oct 22, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-yew Area: The main yew crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When passing Classes in html!, component props don't need .clone(), but element props do

2 participants